<?php
class Catalog {
	var $data     = array();
	var $products = array();
	var $subtotal = 0;
	var $taxes    = array();
	var $total    = 0;
	var $stock    = TRUE;
  	var $shipping = FALSE;
   
  	function __construct(&$locator) {
		$this->config   =& $locator->get('config');
		$this->database =& $locator->get('database');
	}
	
	function getProduct($product_id) {
		return $this->database->getRow("select * from product p left join product_description pd on (p.product_id = pd.product_id) left join image i on (p.image_id = i.image_id) where p.product_id = '" . (int)$request->gethtml('product_id') . "' and pd.language_id = '" . (int)$language->getId() . "' and p.date_available < now() and p.status = '1'");	
	}
	
	function getProductsByCategory($category_id) {
		return $this->database->getRows("select * from product");	
	}
	
	function getFeaturedProducts() {
		return $this->database->getRows("select * from product");	
	}
	
	
	function getSpecialPrice($product_id, $regprice) {
		$special = $this->database->getRow("select distinct * from product_special where product_id = '" . $product_id . "' and status = '1' and date_start <= now() and date_end > now()");
		$newprice = $regprice;
		if ($special) {
			$oldprice = $regprice;
			if ($special['prefix'] == '%') {
				$newprice -= $newprice * ($special['discount']/100);
			} elseif ($special['prefix'] == '-') {
				$newprice -= $special['discount'];
			} else {
				$newprice = $special['discount'];
			}
		}
		
		if ($newprice != $regprice) {
			return $newprice;
		}
	}
}
?>